/* 
自定义发ajax请求的hook函数
*/
import axios from 'axios'
import {ref} from 'vue'

export default function useUrlLoader<T>(url: string) {
  const loading = ref(true)
  const errorMsg = ref('')
  const result = ref<T>()

  axios(url)
    .then(response => {
      loading.value = false
      result.value = response.data
    })
    .catch(error => {
      loading.value = false
      errorMsg.value = error.message
    })

  return{
    loading,
    errorMsg,
    result
  }

}